package org.activequant.core.domainmodel.account.util;

import org.activequant.core.domainmodel.account.BalanceBook;
import org.activequant.core.domainmodel.account.Transaction;
import org.activequant.core.domainmodel.account.TransactionBook;

/**
 * Converts a transaction book to a balance book<br>
 * <br>
 * <b>History:</b><br>
 * - [28.02.2009] Created (Ulrich Staudinger)<br>
 * 
 * @author Ulrich Staudinger
 */
public class BalanceAndTransactionBookConverter {
	/**
	 * returns BalanceBook holding a BalanceEntry for every Transaction in the given aBook(TransactionBook).<br/>
	 * Its currentBalance(double) is also calculated by adding up the sum(double) of each Transaction
	 * @param aBook
	 * @return
	 */
	public static BalanceBook convertTransactionBookToBalanceBook(TransactionBook aBook) {
		BalanceBook myBalanceBook = new BalanceBook();
		for (Transaction myT : aBook.getTransactions()) {
			myBalanceBook.addBalanceEntry(myT.getSum(), myT.getTimeStamp());
		}
		return myBalanceBook;
	}
}
